<template>
  <div class="login-container">
    <el-form ref="loginForm" :model="loginForm" label-width="80px" class="login-form">
      <el-form-item label="账号" prop="username">
        <el-input v-model="loginForm.username" placeholder="请输入账号"></el-input>
      </el-form-item>
      <el-form-item label="密码" prop="password">
        <el-input v-model="loginForm.password" type="password" placeholder="请输入密码"></el-input>
      </el-form-item>
      <el-form-item label="验证码" prop="verifyCode">
        <div class="verify-code">
          <el-input v-model="loginForm.verifyCode" placeholder="请输入验证码"></el-input>
          <img class="verify-img" v-if="captchaImage" @click="changeCaptchaImage" :src="captchaImage" alt="验证码">
        </div>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="login">登录</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import request from "@/util/request";

export default {
  created() {
  this.changeCaptchaImage()
  },
  data() {
    return {
      captchaImage:"",
      loginForm: {
        uuid:"",
        username: '',
        password: '',
        verifyCode: ''
      }
    };
  },
  methods: {
    async changeCaptchaImage(){
      let data= await request("captchaImage")
      console.info(data)
      this.captchaImage=data.image;
      this.loginForm.uuid=data.uuid
    },
    login() {
      console.info(this.loginForm)
      // 登录逻辑
      this.$router.push("/index/user")
    }
  }
};
</script>

<style>
.login-container {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  background-color: #f2f2f2;
}

.login-form {
  width: 400px;
  background-color: #fff;
  padding: 20px;
  border-radius: 5px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.verify-code {
  display: flex;
  align-items: center;
}

.verify-img {
  margin-left: 10px;
  height: 32px;
  cursor: pointer;
}
</style>